@lib.test.Tag("ptestlc2")
def test_nebula_scenario_111_7_db_sync_device_record_crud_no_open(self):
    self.logTestTitle("同步库是关闭状态，绑定后开启同步库")

    self.logTestStep("构造数据库,并执行增改流程,开始是关闭同步状态")
    ak = self.cfg.ak
    device_id = self.cfg.device_id
    db_id = self.cloud.db_sync_new(ak, init_sync_status="NOT_SYNCING")

    self.logTestTitle("插入人像")
    image_name = "xueqi1.jpg"
    image1 = self.cloud.imageToBase64(os.path.join(self.cfg.image_dir, image_name))
    image_name_update = "guojin1.jpg"
    ids = []
    step_list = ["step_1"]
    batch_num = 1
    object_list = []
    for name in step_list:
        objects = []
        for x in range(batch_num):
            _id = self.cloud.getUuid(32)
            ids.append(_id)
            objects.append(
                {
                    "id": _id,
                    "portrait": {
                        "name": "%s_%s" % (name, x),
                        "gender": 0,
                        "age": 18,
                        "phone": "１",
                        "company": "ST",
                        "department": "ST",
                        "job_number": "1",
                        "ic_number": "1",
                        "id_number": "1",
                        "remark": "xxxx",
                        "extra_info": "string",
                        "image": {"data": image1},
                    },
                }
            )
        object_list.extend(objects)
        resp = self.cloud.nebulaDBSyncSrv_portraitBatchAdd(
            ak, db_id, objects=objects
        )
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(
            len(resp.json_get("results")),
            len(objects),
            "返回的结果数目与创建的行数不同%s:%s" % (len(resp.json_get("results")), len(objects)),
        )
        for info in resp.json_get("results"):
            self.assertEqual(
                info["code"],
                200,
                "ERROR:%s,status:%s" % (info["error"], info["status"]),
            )
        time.sleep(2)

    time.sleep(5)
    self.logTestStep("全量更新绑定关系,之前已经有的绑定关系保留，新增一个库")
    self.cloud.device_dbs_batch_update(ak, device_id, db_id)

    time.sleep(5)
    self.logTestStep("启用同步库同步进程")
    resp = self.cloud.dbsync_sync_start_databases(ak=ak, db_id=db_id)
    self.assertEqual(resp.status_code, 200)

    time.sleep(5)
    # 获取同步库状态
    resp = self.cloud.nebulaDBSyncSrv_deviceSyncStatusGet(ak, device_id)
    local_db_id = None
    for state in resp.json_get("sync_states.states"):
        if state["cloud_portrait_db_id"] == db_id:
            local_db_id = state["local_portrait_db_id"]
            break
    else:
        self.assertTrue(None, "states中没有找到cloud_db_id:%s" % db_id)
    self.assertTrue(local_db_id != "", "local_db_id是空")

    self.logTestStep("等待120秒，调用端上接口查看是否同步成功")
    time.sleep(120)
    resp = self.portraitmanager_queryPortraitDbs(db_ids=[local_db_id])
    self.assertEqual(resp.json_get("data.0.db_id"), local_db_id)
    self.assertEqual(resp.json_get("data.0.db_size"), len(step_list) * batch_num)